package com.facebank.usersupport.service.impl;

import com.facebank.usersupport.mapper.usersupport.usersupport.RouteMapper;
import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.model.Route;
import com.facebank.usersupport.service.IRouteService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteServiceImpl implements IRouteService{
    @Autowired
    private RouteMapper routeMapper;

    @Override
    public RestModel add(Route route) {
        route.setCreateTime(System.currentTimeMillis());
        route.setUpdateTime(System.currentTimeMillis());
        int is_success = routeMapper.insertSelective(route);
        if (is_success==1){return new RestModel(RestModel.CODE_SUCCESS, RestModel.MESSAGE_SUCCESS);}
        return new RestModel();
    }

    @Override
    public RestModel delete(Integer id) {
        int is_success = routeMapper.deleteByPrimaryKey(id);
        if (is_success==1){return new RestModel(RestModel.CODE_SUCCESS, RestModel.MESSAGE_SUCCESS);}
        return new RestModel();
    }

    @Override
    public RestModel detail(Integer id) { return new RestModel(routeMapper.selectByPrimaryKey(id)); }

    @Override
    public RestModel list(int pageNo,int length,String routeName, String routeType, Long startTime, Long endTime) {
        PageHelper.startPage(pageNo,length);
        List<Route> routes = routeMapper.selectRouteList(routeName,routeType,startTime,endTime);
        PageInfo<Route> pageInfo =new PageInfo<>(routes);
        return new RestModel(pageInfo);
    }

    @Override
    public RestModel updata(Route route) {
        route.setUpdateTime(System.currentTimeMillis());
        return new RestModel(routeMapper.updateByPrimaryKeySelective(route));
    }

    @Override
    public RestModel search() {
        return new RestModel();
    }
}
